<?php
include("config.php");
//提交验证码后

if($_POST['UserID']&&$_POST['PassWord']&&$_POST['cCode']&&$_POST['session_id']){
	
	//模拟登录
	$snoopy = new Snoopy; 
	$submit_url = $loginurl;
	//定义POST内容
	$submit_vars["__VIEWSTATE"]          = $_SESSION["__VIEWSTATE"];
	$submit_vars["__VIEWSTATEGENERATOR"] = $_SESSION["__VIEWSTATEGENERATOR"];
	$submit_vars['ctl00$txtusername']    = $_POST["UserID"];
	$submit_vars['ctl00$txtpassword']    = $_POST["PassWord"];
	$submit_vars['ctl00$txtyzm']         = $_POST["cCode"];
	$submit_vars['ctl00$ImageButton1.x'] = 46;
	$submit_vars['ctl00$ImageButton1.y'] = 22;

	//模拟HEADER
	$snoopy->agent = $agent;
	$snoopy->host = IP;
	$snoopy->referer = $submit_url;
	$snoopy->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];

	$_SESSION["userID"] = $_POST["UserID"];
	//提交
	$snoopy->submit($submit_url,$submit_vars);

	//超时返回
	if ($snoopy->status != '200' || $snoopy->timed_out) {
    	echo json_err(1,"登录提交超时！");
    	exit;
	}
	
    $snoopy_results = $snoopy->results;

	if(stripos($snoopy_results,"密码错误")){
    	echo json_err(3,"用户名或密码错误！");
    	exit;
	}
	if(stripos($snoopy_results,"你输入的验证码错误")){
    	echo json_err(4,"验证码错误！");
    	exit;
	}

	//如果只验证登录信息，不进行登录后的其他操作
	if(empty($login_do)){
		//noapi调用
		if(!empty($_POST['noapi'])){
			echo "登录成功！";
			return;
		}
		echo json_err(0,'登录成功!');
		return;
	}

}else{
	echo json_err(2,'提交数据不全!');
}

?>
